/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.pig.pigpen.editor.textEditor;

import org.apache.pig.pigpen.editor.PigPenEditor;
import org.apache.pig.pigpen.editor.textEditor.errorHandler.ErrorAnnotation;
import org.apache.pig.pigpen.editor.textEditor.errorHandler.PigValidatorAndMarker;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.FileDocumentProvider;
import org.eclipse.ui.editors.text.TextEditor;

public class PigScriptEditor extends TextEditor {

    private ColorManager colorManager;
    private PigPenEditor plEditor;

    public PigScriptEditor(PigPenEditor ple) {
        super();
        this.plEditor = ple;
        colorManager = new ColorManager();
        setSourceViewerConfiguration(new PigEditorConfiguration(colorManager));
        setDocumentProvider(new FileDocumentProvider());
    }

    public void dispose() {
        colorManager.dispose();
        super.dispose();
    }

    public void doSave(IProgressMonitor monitor) {
        super.doSave(monitor);
        plEditor.doSave(monitor);
    }

    protected void editorSaved() {
        super.editorSaved();

        validateAndMark();

    }

    public void setFocus() {
        super.setFocus();
    }

    public boolean isSaveAsAllowed() {
        return false;
    }

    protected void validateAndMark() {
        IDocument doc = getDocumentProvider().getDocument(getEditorInput());
        new PigValidatorAndMarker(doc, ((IFileEditorInput) getEditorInput())
                .getFile());

    }

}
